<?php 
  include_once("../../../../../config.php");
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <script src="/application/right_plane/js.js"></script>
  </head>
<body>
  <?php
    //拼接查询条件
    if($_REQUEST['text']){
      $con = "name like '%".$_REQUEST['text']."%' AND (relation = '无' or relation = '' or relation is NULL )";
    }
    //模糊查询并将结果循环输出到页面上
    $unit_list = select_lines_all_items($table_Prefix . "unit", "nid desc", $con, "100");
    //无数据时
    if(!count($unit_list)){
      echo "<p>无匹配企业，点击关闭将按当前输入内容新增企业</p>";
      exit;
    }
  ?>
  <div class="layui-form">
    <table class="layui-table">
      <colgroup>
        <col width="50">
        <col width="200">
        <col width="50">
      </colgroup>
      <thead>
        <tr>
          <th>序号</th>
          <th>企业名称</th>
          <th>操作</th>
        </tr> 
      </thead>

      <tbody>
        <?php
          for($i = 0;$i < count($unit_list); $i++){
        ?>
          <tr>
            <td><?php echo $i + 1;?></td>
            <td><?php echo $unit_list[$i]['name'] ?></td>
            <td><button class="layui-btn layui-btn-sm opt-unit" data-unitnid="<?php echo $unit_list[$i]['nid']?>" data-unitname="<?php echo $unit_list[$i]['name']?>">选择</button></td>
          </tr>
        <?php
          }
        ?>
      </tbody>
    </table>
  </div>
</body>
<script>
  $('.opt-unit').click(function(){
    // 获取企业ID和名称
    var unitnid  = $(this).data('unitnid');
    var unitname = $(this).data('unitname');
    // 赋值
    $('input[name="ai_unit_nid"]').val(unitnid);
    $('input[name="ai_unitname"]').val(unitname);
    // 收缩侧边栏
    close_ajax_content();
  })
</script>
</html>